for _ in range(int(input())):
n, l, k = int(input()), list(map(int, input().split())), False
for i in range(n):
if l[i:].count(l[i]) == 2:
if l[i+1] != l[i]:
print("YES")
k = True
break
elif l.count(l[i]) > 2:
print("YES")
k = True
break
if k == False:
print("NO")
// Problem: B. Yet Another Palindrome Problem
// Contest: Codeforces - Codeforces Round #627 (Div. 3)
// URL: https://codeforces.com/problemset/problem/1324/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
/*
#WTFyouhere
♕ABHINAV♕
HUSTLE KARO BHASAD NHI.....
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
const unsigned int M = 1000000007;
//►►►►►►►►►►►►►►►►►►►►(⊙⊙)(☉_☉)(⊙⊙)►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►
ll power(ll a, ll b, ll m = M) {a %= m;ll res = 1;while (b > 0) {
if (b & 1)res = res * a % m;a = a * a % m;b >>= 1;}return res;}
ll gcd(ll x, ll y) {return (x ? gcd(y % x, x) : y);}
ll inv(ll n, ll m = M) {return power(n, m - 2, m);}
ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
ll nextgreaterelement(ll n) {auto digits = to_string(n);
next_permutation(begin(digits), end(digits));auto res = stoll(digits);return res;}
vector<int> factorize(int n) {vector<int> ans;for (int i = 2; i * i <= n; ++i) {
while (n % i == 0) {ans.push_back(i);n /= i;}}if (n != 1) {ans.push_back(n);}
for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";}
ll near_pow(ll q){ll ans = (ll)log2(q);return pow(2,ans);}
long long ceil(long long p, long long q) {if(p % q == 0) return (p / q);return (p / q) + 1;}
//►►►►►►►►►►►►►►►►►►►(⊙⊙)(☉_☉)(⊙⊙)►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►
void reply()
{
ll t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int a[n];
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
bool flag=0;
for(int i=1;i<=n;i++)
{
for(int j=i+2;j<=n;j++)
{
if(a[i]==a[j])
{
flag=1;
break;
}
}
}
if(flag)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
int main() {
// your code goes here
reply();
}
221A - Little Elephant and Function | 492C - Vanya and Exams |
1369B - AccurateLee | 892B - Wrath |
999A - Mishka and Contest | 727C - Guess the Array |
1625C - Road Optimization | 1715D - 2+ doors |
267A - Subtractions | 1582A - Luntik and Concerts |
560A - Currency System in Geraldion | 946A - Partition |
1068B - LCM | 1692E - Binary Deque |
679A - Bear and Prime 100 | 488A - Giga Tower |
14A - Letter | 1150A - Stock Arbitraging |
1552A - Subsequence Permutation | 1131F - Asya And Kittens |
1475F - Unusual Matrix | 133B - Unary |
1547A - Shortest Path with Obstacle | 624A - Save Luke |
1238A - Prime Subtraction | 1107C - Brutality |
1391B - Fix You | 988B - Substrings Sort |
312A - Whose sentence is it | 513A - Game |